{extend name="common:frm_base" /}
{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">车队名称</label>
                    <div class="layui-input-block">
                        <select name="business_id">
                            <option value="">请选择车队</option>
                            {foreach $business as $key=>$val}
                            <option value="{$val->id}">{$val->name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">司机名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <!--<button class="layui-btn layuiadmin-btn-useradmin" data-type="batchdel">删除</button>-->
                <!--<button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button>-->
            </div>

            <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
            <script type="text/html" id="iconTpl">
                <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.icon }}>
            </script>
            <script type="text/html" id="stateTpl">
                {{#  if(d.is_state == 1){ }}
                <input type="checkbox" lay-filter="status_change" field="{{d.status_field}}" table_name="{{d.status_table}}"
                       id="{{d.id}}" checked disabled lay-skin="switch" lay-text="已审核|未审核">
                {{#  } else { }}
                <input type="checkbox" lay-filter="status_change" field="{{d.status_field}}" table_name="{{d.status_table}}"
                       id="{{d.id}}" disabled lay-skin="switch" lay-text="已审核|未审核">
                {{#  } }}
            </script>
            <script type="text/html" id="table-useradmin-webuser">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="state"><i
                        class="layui-icon layui-icon-edit"></i>审核</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                        class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script>


    layui.config({
        base: '__LAYUIADMIN__/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table;

        //监听搜索
        form.on('submit(LAY-user-front-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('LAY-user-manage', {
                where: field
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //刷新列表
        var reloadTable = function (field) {
            table.reload('LAY-user-manage', {
                where: field
            });
        }


        //用户管理
        table.render({
            elem: '#LAY-user-manage'
            , url: "{:url('driver/ajaxIndex')}" //模拟接口
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', width: 100, title: 'ID', sort: true}
                , {field: 'name', title: '司机名称', minWidth: 100}
                , {field: 'business_name', title: '车队名称', minWidth: 100}
                , {field: 'score', title: '服务平均分', minWidth: 100}
                , {field: 'service_number', title: '服务次数', minWidth: 100}
                , {field: 'is_state', title: '审核状态', templet: '#stateTpl', minWidth: 80, align: 'center'}
                , {field: 'status', title: '状态', minWidth: 80, align: 'center'}
                , {field: 'create_time', title: '添加时间', sort: true,}
                , {title: '操作', width: 300, align: 'center', fixed: 'right', toolbar: '#table-useradmin-webuser'}
            ]]
            , method: 'post'
            , where: {is_state:0}
            , page: true
            , limit: 30
            , height: 'full-220'
            , text: '对不起，加载出现异常！'
        });

        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
            var type = $(this).data('type');
            var url = "";
            if (type == 'add') {
                url = "{:url('Driver/state_add')}";
            }
            active[type] ? active[type].call(this, url, table) : '';
        });

        table.on('tool(LAY-user-manage)', function (obj) {
            var data = obj.data;
            tool_even(obj, data, reloadTable);
            if (obj.event == 'state') {
                var view_url = "state_add?id="+data.id;
                layer.open({
                    type: 2
                    , title: '审核司机'
                    , content: view_url
                    , maxmin: true
                    , area: ['80%', '90%']
                    , shadeClose: true
                    , scrollbar: false
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-front-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (form) {
                            var field = form.field; //获取提交的字段

                            //提交 Ajax 成功后，静态更新表格中的数据
                            $.ajax({
                                url: form.form.action,
                                data: field,
                                type: 'POST',
                                success: function (res) {
                                    if (res.code == 0) {
                                        layer.alert(res.msg);
                                        layer.close(index); //关闭弹层
                                        reloadTable();
                                    } else {
                                        layer.alert(res.msg);
                                    }
                                }
                            });

                        });

                        submit.trigger('click');
                    }
                    , success: function (layero, index) {

                    }
                });
            }
        });


    });
</script>
</body>
</html>
{/block}
